%% Bestimcell.m
% - this file sets up estimation results of transition parameters
% for different cells:
%    sample 2 (benchmark): cells by socio-econ. chars & macro conditions
%    sample 7 one cell: sample with only post-2000 data
%    sample 8 cells by occupations
%    sample 9 cells by regions
% => for calculation of standard errors using "standarderror.m"
% => for calculation of welfare costs using "Calgo.m"
% - for whole sample (pooled across groups), use "Bestim.m"
% - alternative to empirical data is simulated data - see "Asimul.m"
% - data on wages (estimated parameters and sample sizes) comes from 
%           5_sample2_wages_distribution.xls,
%           5_sample7_wages_distribution.xls, 
%           5_sample8_wages_distribution.xls
%           5_sample9_wages_distribution.xls
% which summarizes different coal vs. non-coal parameters across groups
% - data on transition parameters (estimated parameters and sample sizes)
%            5sample2_wholesampleAndcells_estimates_Censoring
%            5sample7_wholesampleAndcells_estimates_Censoring
%            5sample8_wholesampleAndcells_estimates_Censoring
%            5sample9_wholesampleAndcells_estimates_Censoring

%% estimation results for different cells %%
%% (and for 4 cells also for different ages) 
%
% 12 different groups Nx=12
% order of results: (!) unclear whether 50+ or 51+ years old
%{
sample=2
1 - Low Educ, 18-30 y/o, high unemp
2 - Low Educ, 18-30 y/o, low unemp
3 - Low Educ, 31-49 y/o, high unemp
4 - Low Educ, 31-49 y/o, low unemp
5 - Low Educ, 50+ y/o, high unemp
6 - Low Educ, 50+ y/o, low unemp
7 - Hi Educ, 18-30 y/o, high unemp
8 - Hi Educ, 18-30 y/o, low unemp
9 - Hi Educ, 31-49 y/o, high unemp
10- Hi Educ, 31-49 y/o, low unemp
11- Hi Educ, 50+ y/o, high unemp
12- Hi Educ, 50+ y/o, low unemp

sample=7
1 - pre-2000 data
2 - post-2000 data

sample=8
1 "Maschinen-Fahrzeugtechnikberufe"
2 "Unternehmensf�hrung,-organisation"
4 "F�hrer/innenFahrzeug-,Transportger�ten"
5 "Metallerzeugung-bearbeitung,Metallbauberufe"
6 "Verkehrs-,Logistikberufe(au�erFahrzeugf�hrung)"
7 "TechnischeForschungs-Entwicklungsberufe"
8 "Hoch-Tiefbauberufe"
9 "Rohstoffgewinnung-aufbereitung,Glas-Keramik"
10 "Mechatronik-Energie-Elektroberufe"
11 "Geb�ude-versorgungstechnische Berufe"
12 "Other occupations"

sample=9
1 "Lausitzer Revier" 
2 "Mitteldt. Revier" 
3 "Helmstedter Revier" 
4 "Rheinisches Revier" 
5 "Other West Ger" 
6 "Other East Ger"
%}
clear;clc;
cd (Folder Location - to be added by user, LH) 

%% Samples / Robustness tests
% (see 00master / 5estimation.do on sample definition) 
% sample=2 is the default: cells are cells 1-24 cut by age/educ/macro
% sample=7 cuts data into two: (1) pre-2000; (2) post-2000s
% sample=8 cuts data by occupations
% sample=9 cuts data by regions

 sample=2

%% wage parameters
% NB. these are values of the log-normal distribution

if sample==2
    param.wCmu  =  [7.345960653 7.281774657 7.699694214 8.04024648 7.692924775 8.033408676 7.646285435 7.88251108 7.697495857 8.055569268 7.680026803 8.196791763];
    param.wNCmu =  [7.332194149 7.510706561 7.325326602 7.596960423 7.256033187 7.554594976 7.348344181 7.554952547 7.386615283 7.637702515 7.398925208 7.6726841];
    param.wCsig =  [0.5241428   0.712674833 0.279197974 0.280104343 0.284615149 0.107177545 0.21950775 0.296982895 0.259949158 0.26156387 0.312019997 0.430567932]; 
    param.wNCsig = [0.288064675 0.374075079 0.291435508 0.275323238 0.338962141 0.394020121 0.265427726 0.316380972 0.252478415 0.304230142 0.333248199 0.436872645]; 

    param.wCmulevel =   [1762.743501 1840.84938 2302.134168 3210.801361 2294.645249 3098.251012 2142.318512 2754.111552 2284.723928 3292.458047 2301.684021 3925.927141]; 
    param.wCsiglevel =  [879.9198395 1165.063495 730.2817332 723.3801842 741.9151545 353.4320778 475.4276318 696.6181667 797.0085514 1187.600545 1065.95415 2707.774145];
    param.wNCmulevel =  [1593.293617 1951.792324 1583.844503 2063.962848 1486.904732 2077.497188 1608.116969 1997.539764 1665.643568 2170.729383 1731.721146 2366.995721 ]; 
    param.wNCsiglevel = [472.2907973 694.9652522 475.3711183 536.4583809 429.4298063 1140.314652 441.6070428 575.5155009 427.8660458 668.2648116 672.0612702 1305.436289];

elseif sample==7
    param.wCmu  =  [7.652575171370];
    param.wNCmu =  [7.324437497894];
    param.wCsig =  [0.505323829299];
    param.wNCsig = [0.384629126276];
    param.wCmulevel =   [2363.579777];
    param.wCsiglevel =  [1570.039335];
    param.wNCmulevel =  [1632.411824];
    param.wNCsiglevel = [733.7166203];

elseif sample==8
    param.wCmu  =  [7.6187232682503 7.71069949238237 7.61239210164026 7.71004206717368 7.67363202280416 7.87866374656409 7.53432377387788 7.77954398337403 7.79465371126617 7.7616583938568 7.58445155682269];
    param.wNCmu =  [7.41254595986795 7.33896489129609 7.4353200026397 7.42436421185756 7.29751790295301 7.52914311424944 7.3649637297019 7.55808153094217 7.47650886909164 7.37596181609172 7.2209373340122 ];
    param.wCsig =  [0.313055892179984 0.432263794567641 0.208982741756534 0.304372480125123 0.228653235883146 0.327212366939044 0.242347900712648 0.333482877757832 0.282151604616593 0.216348879348476 0.297455288662851 ];
    param.wNCsig = [0.257154479065289 0.348584170532896 0.277323745692511 0.294171763840231 0.321718648857757 0.33888875722332 0.242337048356683 0.273327637117158 0.375600871910143 0.235883553761506 0.346159102253556 ];

    param.wCmulevel =   [2129.01213147378 2461.98467505162 2067.97232222595 2352.44857635867 2208.92609531299 2778.21300760495 1926.27806967843 2524.07800171061 2555.57888916016 2403.51925463195 2058.55182522761 ];
    param.wCsiglevel =  [628.355042500863 1433.47824212226 452.667709894154 1012.75020299314 543.059586697088 930.475087433188 487.456021453423 857.743373839742 1230.75722982609 523.147756067056 678.025675749475];
    param.wNCmulevel =  [1714.44043304423 1634.59766343337 1759.35201480947 1749.65264588933 1548.78617965675 1976.72857737991 1626.3739199431 1984.45380273601 1908.12953162006 1639.89296459284 1451.93587621264];
    param.wNCsiglevel = [492.414815287768 614.54013224015 489.068951658499 533.315481806137 469.120317348094 747.616574733491 402.639413202788 520.828171202114 944.045324096203 381.613051212018 573.802817617355];

elseif sample==9
    param.wCmu  =  [7.68339451741056 7.58750849384311 7.87372983748794 7.94423541036439 7.88518117666964 7.25795648803195 ];
    param.wNCmu =  [7.26267505402821 7.30369320344683 7.43086570614037 7.57419139232724 7.56677193376463 7.31571224875822 ];
    param.wCsig =  [0.326709546487409 0.227497447653225 0.393750900811716 0.457064287866464 0.476362963180456 0.269990808289568 ];
    param.wNCsig = [0.301806358196956 0.292637252959878 0.407828400754002 0.462320286546492 0.348359317912908 0.302308508047192 ];

    param.wCmulevel =   [2283.48320591656 2027.69630750792 2847.20878270467 3146.39627292415 2912.61153087235 1475.54642486572 ];
    param.wCsiglevel =  [743.953967386487 524.050963584671 1440.41011749978 1992.84088892266 1174.41631157226 472.17854971793 ];
    param.wNCmulevel =  [1489.67066177078 1547.42601343621 1847.42995938388 2161.84768782251 2046.24032725219 1573.5289344312 ];
    param.wNCsiglevel = [451.145197999121 442.997023465612 979.068064469128 1258.47470160201 717.40238323766 493.016502168819 ];
end    
    
%% transition parameters & underlying transitions
% - taken from empirics/results wholesampleandCells (NB.first value is for whole sample)
% - Original is *daily* transition rates. Here (small probabilities)
% approximating monthly transition rates from daily transition rates by
% multiplying.

if sample==2
    %% (for rho, NB. age-specific variants - by cell - below)
    param.rho   = 30.5.*[0.000000000000 0.000000000000 0.000000595569 0.000001869651 0.000140110501 0.000074425360 0.000000000000 0.000000000000 0.000001156777 0.000000597549 0.000129686616 0.000075222930];
    param.deltaC= 30.5.*[0.000126222795 0.000111056058 0.000025884324 0.000049078332 0.000005626494 0.000008226452 0.000343037755 0.000101205885 0.000102595371 0.000035016395 0.000026486049 0.000009014542];
    param.deltaNC=30.5.*[0.000481862144 0.000418951049 0.000260229093 0.000317746870 0.000069694804 0.000110525180 0.001014784552 0.000702307628 0.000638785880 0.000289344481 0.000335514904 0.000137067921];
    param.lamC  = 30.5.*[0.001259181532 0.000171973777 0.000829806655 0.000164062180 0.000315284669 0.000049516138 0.001555875374 0.000288703785 0.000774880009 0.000282209997 0.000414968507 0.000131683113];
    param.lamNC = 30.5.*[0.000314795383 0.002565848759 0.000165961331 0.001389059787 0.000066375720 0.000209491355 0.000855731456 0.002426794818 0.000370091945 0.001677339322 0.000118562431 0.000398789450];
    param.lamZC = 30.5.*[0.002211934156 0.004051102976 0.001799605248 0.002101268517 0.000198004118 0.000516375071 0.002923736054 0.004869275086 0.002721226411 0.003035167148 0.000956256198 0.001015110290];

elseif sample==7 % use group=2 
    param.rho   = 30.5.*[0.000049773599];
    param.deltaC= 30.5.*[0.000037578119];
    param.deltaNC=30.5.*[0.000418117322];
    param.lamC  = 30.5.*[0.000215728440];
    param.lamNC = 30.5.*[0.001132513092];
    param.lamZC = 30.5.*[0.001901880197];

elseif sample==8 % 
    param.rho   = 30.5.*[0.000055113070 0.000090637526 0.000064498285 0.000077518877 0.000081693868 0.000094721019 0.000078330902 0.000034275361 0.000045885495 0.000050284198 0.000092533228 ];
    param.deltaC= 30.5.*[0.000068894753 0.000067885256 0.000101539848 0.000074271011 0.000117782838 0.000053703030 0.000171771095 0.000027306808 0.000047220383 0.000030293466 0.000092287135 ];
    param.deltaNC=30.5.*[0.000286228398 0.000238272829 0.000563985281 0.000415572840 0.000498247008 0.000212286784 0.000967384219 0.000310324011 0.000136938305 0.000511175881 0.000500157506 ];
    param.lamC  = 30.5.*[0.000097225806 0.000108329669 0.000196156912 0.000245526625 0.000082325062 0.000098902810 0.000218377349 0.000065941535 0.000051565933 0.000272857023 0.000180079736 ];
    param.lamNC = 30.5.*[0.000677375395 0.000507143339 0.000835084194 0.000661724196 0.000428090325 0.000378776720 0.000971958200 0.000379586530 0.000624520747 0.000906025243 0.001089592986 ];
    param.lamZC = 30.5.*[0.001886051081 0.001229794382 0.002683337287 0.002372645828 0.001875808124 0.001329254711 0.001801959775 0.001180334885 0.002297067221 0.001982203664 0.001686728808 ];

elseif sample==9 % 
    param.rho   = 30.5.*[0.000095345044 0.000086603158 0.000072367007 0.000051629153 0.000096571010 0.000023332141 ];
    param.deltaC= 30.5.*[0.000110788657 0.000308031901 0.000022075166 0.000006505343 0.000060947272 0.000297919149 ];
    param.deltaNC=30.5.*[0.000536940605 0.000556822492 0.000298653526 0.000174946674 0.000304303859 0.000592223997 ];
    param.lamC  = 30.5.*[0.000703272660 0.000772891387 0.000535605600 0.000566650494 0.000145567845 0.001934235977 ];
    param.lamNC = 30.5.*[0.000249075734 0.000298115249 0.000121728545 0.000208952369 0.000927518237 0.001289490651 ];
    param.lamZC = 30.5.*[0.001422336742 0.001472607593 0.001399054785 0.001151152308 0.001828643956 0.001639721977 ];
end

if sample==2 
    %% NOW here only for sample 2: age-specific variants for rho - by cell
    % set retirement probability rho to zero for groups aged less than 50
    for i=[3,4,9,10]
        param.rho(i)=0;
    end
    % age-specific retirement probabilities for the 4 cells of plus-50s
    % take these values from 5_ages.xlsx produced by 5estimation.do
    % parameter vectors for cells 5,6,11,12 with dim(age50:age65) agespecific
    % rhos (used in Asimulage.m that calls this Bestimcell.m)
    % report DAILY rho values here
    param.rhod5= [0.000009420044 0.000034968628 0.000042255618 0.000048492995 0.000092838450 0.000153463292 0.000152380059 0.000139485665 0.000142787759 0.000226660305 0.000248324673 0.000195689818 0.000222632319 0.000312620652 0.000209441954 0.000326413370]; %[rho-age50-cell5 rho-age51-cell5 ...]
    param.rhod6= [0.000030171787 0.000033207730 0.000016529472 0.000029454647 0.000042325189 0.000120860165 0.000043986638 0.000052624610 0.000059818391 0.000087112456 0.000142407683 0.000141692030 0.000164454958 0.000390571723 0.000159476916 0.000396615547];
    param.rhod11=[0.000009110628 0.000022985155 0.000028432914 0.000029530046 0.000090903771 0.000202132974 0.000215974626 0.000230580170 0.000141425237 0.000175380850 0.000206385333 0.000114544939 0.000149833371 0.000237736683 0.000147761084 0.000255383766];
    param.rhod12=[0.000006728039 0.000014737227 0.000010711316 0.000014727284 0.000017856113 0.000062647329 0.000039520966 0.000037283101 0.000041864213 0.000043619075 0.000067699426 0.000081369040 0.000221179008 0.000583200950 0.000382586517 0.000642762953];
    param.rhoy5 = 1-(1-param.rhod5).^365;
    param.rhoy6 = 1-(1-param.rhod5).^365;
    param.rhoy11= 1-(1-param.rhod5).^365;
    param.rhoy12= 1-(1-param.rhod5).^365;

    % age-specific sample sizes (used in Asimulage.m that calls this Bestimcell.m)
    % assuming good macro conditions: uneven-numbered cells empty:
    param.ageN1=zeros(65-17,1);
    param.ageN3=zeros(65-17,1);
    param.ageN5=zeros(65-17,1);
    param.ageN7=zeros(65-17,1);
    param.ageN9=zeros(65-17,1);
    param.ageN11=zeros(65-17,1);

    % pre-assigning even-numbered vectors: these will be filled below
    param.ageN2=zeros(65-17,1);
    param.ageN4=zeros(65-17,1);
    param.ageN6=zeros(65-17,1);
    param.ageN8=zeros(65-17,1);
    param.ageN10=zeros(65-17,1);

    % take these from 5_age.xls produced by 5estimation.do - "distrib_age_coal2017"
    % cell 2 & 8 are empty for older than 30-y.o.
    param.ageN2(1:30-17,1)=[96 102 95 65 44 50 58 39 56 91 74 62 60];
    param.ageN2(31-17:65-17,1)=0;
    param.ageN8(1:30-17,1)=[0 5 29 78 87 89 99 95 95 149 137 118 137];
    param.ageN8(31-17:65-17,1)=0;
    % cell 4 & 10 are empty for younger than 31 and older than 49
    param.ageN4(1:30-17,1)=0;
    param.ageN4(31-17:49-17,1)=[46 15 26 54 52 32 22 4 7 1 6 0 0 1 1 4 15 23 25];
    param.ageN4(50-17:65-17,1)=0;
    param.ageN10(1:30-17,1)=0;
    param.ageN10(31-17:49-17,1)=[155 186 152 117 97 103 86 55 51 62 71 69 73 70 82 145 190 179 224 ];
    param.ageN10(50-17:65-17,1)=0;
    % cell 6 & 12 are empty for younger than 50
    param.ageN6(1:49-17,1)=0;
    param.ageN6(50-17:65-17,1)=[32 76 88 90 104 96 121 78 67  52 30 31 27 23 3 0 ];
    param.ageN12(1:49-17,1)=0;
    param.ageN12(50-17:65-17,1)=[255 341 358 406 436 501 524 400 428 412 411 347 312 211 44 14];
end

if sample==2
    % Number of transitions (NB. we have #transitions, #persons, #time at risk)
    T.rho =     [0 0 13 4 3903 510 0 0 97 5 13394 1532];
    T.lamC =    [12 25 20 60 19 39 40 446 67 1293 84 845];
    T.lamNC =   [3 373 4 508 4 165 22 3749 32 7691 24 2559];
    T.deltaC =  [701 117 565 105 157 56 4320 211 8602 293 2762 179]; 
    T.lamZC =   [43 1152 31 1165 5 423 462 21815 1610 76715 729 31396];
    T.deltaNC=  [1144 394 1077 427 250 191 19781 5648 65105 16176 22390 6852];
    % to be updated 17th Dec 2022
    T.wC =      [644 110 481 99 115 41 3831 197 7238 264 1966 133];
    T.wNC=      [132 32 174 84 64 50 2019 353 4812 631 1358 270];

elseif sample==7 % use group 2 for post-2000
    T.rho =     [4970];
    T.lamC =    [881];
    T.lamNC =   [4625];
    T.deltaC =  [3688]; 
    T.lamZC =   [118606];
    T.deltaNC=  [109886];
    % sample sizes below taken from 5_sample7_wages_distribution (sum_w)
    T.wC =      [2863];
    T.wNC=      [2930];        
elseif sample==8 
    % samples takes from number of transitions 
    T.rho =     [3905   3080 2407 2546 1836 2468 964 1093 393 842 4614 ];
    T.lamC =    [182    135   346   82  65    47 122    78 54   78 2687 ];
    T.lamNC =   [1268   632   1473 221 338   180 543   449 654 259 16258 ];
    T.deltaC =  [4905  2346   3799 2459 2663 1418 2139 870 406 511 4635 ]; 
    T.lamZC =   [11568 6754  19861 8059 6730 1819 19525 2118 7832 5742 81756 ];
    T.deltaNC=  [16932 9734 20653 15942 10235 3850 26437 2288 2166 5759 62260 ];
    % sample sizes below taken from 5_sample_wages_distribution (sum_w)
    T.wC =      [4123 2013 3181 2065 2311 1241 1894 751 350 436 3908 ];
    T.wNC=      [1491 1300  940 1196 643  424  2392 149 254 577 6026 ];        
elseif sample==9 
    T.rho =     [8149 3908 2089 8847 1155 3 ];
    T.lamC =    [144 70 22 160 3473 3 ];
    T.lamNC =   [51 27 5 59 22129 2 ];
    T.deltaC =  [9567 14043 644 1119 734 39 ]; 
    T.lamZC =   [2208 1777 82 747 166419 427 ];
    T.deltaNC=  [67933 53395 1568 8870 28896 13015];
    % sample sizes below taken from 5_sample_wages_distribution (sum_w)
    T.wC =      [8855 11540 360 857 651   8 ];
    T.wNC=      [5839   6451 77 405 1659 802 ];        
end
    %% calculate standard errors and confidence intervals for parameters
    [error.rho,     cilo.rho,   cihi.rho]       = standarderror(param.rho,T.rho);
    [error.deltaC,  cilo.deltaC,cihi.deltaC]    = standarderror(param.deltaC, T.deltaC);
    [error.deltaNC, cilo.deltaNC,cihi.deltaNC]  = standarderror(param.deltaNC,T.deltaNC);
    [error.lamC,    cilo.lamC,  cihi.lamC]      = standarderror(param.lamC,T.lamC);
    [error.lamNC,   cilo.lamNC, cihi.lamNC]     = standarderror(param.lamNC,T.lamNC);
    [error.lamZC,   cilo.lamZC, cihi.lamZC]     = standarderror(param.lamZC,T.lamZC);
    [error.wC,   ~ , ~ ]     = standarderror(param.wCsiglevel,T.wC);
    [error.wNC,   ~ , ~ ]     = standarderror(param.wNCsiglevel,T.wNC);
    
% NB. these are parameters of the *log-*normal distribution
% taken from empirics/results/Wage_distribution

%% Display estimated transition paras (input above) and standard errors by cells
makelabels=0;
Nx=length(param.rho);
matcells=NaN(16,Nx);
rlabmatcells = {'$\delta^{C}$', '(s.e.)','$\delta^{NC}$', '(s.e.)','$\lambda^{NC}$','(s.e.)','$\lambda^{C}$','(s.e.)','$\lambda^{ZC}$','(s.e.)','$\rho$','(s.e.)','$w_T^{C}$','(s.e.)','$w_{t_0}^{NC}$','(s.e.)'};
clabmatcells = {'\textbf{1 Low Edu, 18-30, high unem}','\textbf{2 Low Edu, 18-30, low unem}','\textbf{3 Low Edu, 31-49, high unem} ','\textbf{4 Low Edu, 31-49, low unem}','\textbf{5 Low Edu, 50+, high unem}','\textbf{6 Low Edu, 50+, low unem}','\textbf{7 Hi Edu, 18-30, high unem}','\textbf{8 Hi Edu, 18-30, low unem}','\textbf{9 Hi Edu, 31-49, high unem}','\textbf{10 Hi Edu, 31-49, low unem}','\textbf{11 Hi Edu, 50+, high unem}','\textbf{12 Hi Edu, 50+, low unem}'};
% for appendix table on results by group
matcells(1,:) = param.deltaC;
matcells(2,:) =  error.deltaC;
matcells(3,:) = param.deltaNC;
matcells(4,:) =  error.deltaNC;
matcells(5,:) = param.lamNC;
matcells(6,:) = error.lamNC;
matcells(7,:)=param.lamC;
matcells(8,:) = error.lamC;
matcells(9,:)=param.lamZC;
matcells(10,:) = error.lamZC;
matcells(11,:)=param.rho;
matcells(12,:) =  error.rho;
matcells(13,:)=param.wCmulevel;
matcells(14,:)=error.wC;
matcells(15,:)=param.wNCmulevel;
matcells(16,:)=error.wNC;
% output results to latex
path= '../../../paper/' ;
if sample==2
    file='tranestbase.tex';
elseif sample==7
    file='tranestsamp7.tex';
elseif sample==8
    file='tranestsamp8.tex';
elseif sample==9
    file='tranestsamp9.tex';
end
filename= [path file];
matrix2latex(matcells, filename, 'rowLabels', rlabmatcells, 'columnLabels', clabmatcells, 'alignment', 'c', 'format', '%-6.8f', 'size', 'small');

%% display standard errors of transition parameters
%% results for different groups
makelabels=0;
Nx=length(param.rho);
matse=NaN(15,Nx);
rlabse = {'s.e.rho', 'CI-high rho', 'CI-low rho','s.e.deltaC', 'CI-hi deltaC', 'CI-lo deltaC','s.e.deltaNC','CI-hi deltaNC','CI-lo deltaNC', 's.e.lamC', 'CI-hi lamC', 'CI-lo lamC', 's.e.lamNC', 'CI-hi lamNC', 'CI-lo lamNC','s.e.lamZC', 'CI-hi lamZC', 'CI-lo lamZC'};
clabse = {'\textbf{1 Low Edu, 18-30, high unem}','\textbf{2 Low Edu, 18-30, low unem}','\textbf{3 Low Edu, 31-49, high unem} ','\textbf{4 Low Edu, 31-49, low unem}','\textbf{5 Low Edu, 50+, high unem}','\textbf{6 Low Edu, 50+, low unem}','\textbf{7 Hi Edu, 18-30, high unem}','\textbf{8 Hi Edu, 18-30, low unem}','\textbf{9 Hi Edu, 31-49, high unem}','\textbf{10 Hi Edu, 31-49, low unem}','\textbf{11 Hi Edu, 50+, high unem}','\textbf{12 Hi Edu, 50+, low unem}'};
for xn=1:Nx
    matse(1,xn) = error.rho(xn);
    matse(2,xn) = cilo.rho(xn);
    matse(3,xn) = cihi.rho(xn);
    matse(4,xn) = error.deltaC(xn);
    matse(5,xn) = cilo.deltaC(xn);
    matse(6,xn) = cihi.deltaC(xn);
    matse(7,xn) = error.deltaNC(xn);
    matse(8,xn) = cilo.deltaNC(xn);
    matse(9,xn) = cihi.deltaNC(xn);
    matse(10,xn) = error.lamC(xn);
    matse(11,xn) = cilo.lamC(xn);
    matse(12,xn) = cihi.lamC(xn);
    matse(13,xn) = error.lamNC(xn);
    matse(14,xn) = cilo.lamNC(xn);
    matse(15,xn) = cihi.lamNC(xn);
    matse(16,xn) = error.lamZC(xn);
    matse(17,xn) = cilo.lamZC(xn);
    matse(18,xn) = cihi.lamZC(xn);

end
% output results to latex
path= '../../../paper/' ;
if sample==2
    file='transecells.tex';
elseif sample==7
    file='transecell7.tex';
elseif sample==8
    file='transecell8.tex';
elseif sample==9
    file='transecell9.tex';
end
filename= [path file];
matrix2latex(matse, filename, 'rowLabels', rlabse, 'columnLabels', clabse, 'alignment', 'c', 'format', '%-6.8f', 'size', 'small');

%% Calculate welfare cost, coal value & unemp value with *** Calgo.m ***
if exist('rlab','var')==0
    makelabels=1;
    rlab=strings(size([1,Nx]));
end
for xn=1:Nx
    if makelabels==1 %check whether we have labelled the groups already in calling file
        disp('for group '); disp(xn)
        rlabx= num2str(xn);
        rlab(xn)= {['group' rlabx]}; % generic group names 
    end
end
if sample==2
    rlab={'1 Low Edu, 18-30, high unem' '2 Low Edu, 18-30, low unem' '3 Low Edu, 31-49, high unem' '4 Low Edu, 31-49, low unem' '5 Low Edu, 50+, high unem' '6 Low Edu, 50+, low unem' '7 Hi Edu, 18-30, high unem' '8 Hi Edu, 18-30, low unem' '9 Hi Edu, 31-49, high unem' '10 Hi Edu, 31-49, low unem' '11 Hi Edu, 50+, high unem' '12 Hi Edu, 50+, low unem'};
elseif sample==7
    rlab={'post-2000 data only'};
elseif sample==8
    rlab={'Maschinen-Fahrzeugtechnikberufe' 'Unternehmensf�hrung,-organisation' 'empty' 'Fuehrer/innenFahrzeug-,Transportgeraeten' 'Metallerzeugung-bearbeitung,Metallbauberufe' 'Verkehrs-,Logistikberufe(ausserFahrzeugf�hrung)' 'TechnischeForschungs-Entwicklungsberufe' 'Hoch-Tiefbauberufe' 'Rohstoffgewinnung-aufbereitung,Glas-Keramik' 'Mechatronik-Energie-Elektroberufe' 'Gebaeude-versorgungstechnische Berufe' 'Other occupations'};
elseif sample==9
    rlab={'Lausitzer Revier' 'Mitteldt. Revier' 'Helmstedter Revier' 'Rheinisches Revier' 'Other West Ger'  'Other East Ger'};
end

if sample==2
    data.label= 'rescells.tex';
elseif sample==7
    data.label= 'rescell7.tex';
elseif sample==8
    data.label= 'rescell8.tex';
elseif sample==9
    data.label= 'rescell9.tex';
end
fut=1;
Calgo

